<%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/extjs.jsp"%>
<html>
<head>
<%@include file="/common/meta.jsp" %>
<title></title>
<link href="${ctx}/pages/longtian/order/css/order.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="${ctx}/styles/longtian/main.css">
</head>
<body>
		<h6 align="center" style="margin-top: 30px;margin-bottom: 15px;">我的购物车</h6>
		<table width="1000" style="margin-top: 0px;" class="yellow_border4" align="center" >
			<tr class="cartTableHeader">
				<td>NO.</td>
				<td>图片</td>
				<td>图书名称</td>
				<td>单价</td>
				<td>优惠</td>
				<td>数量</td>
				<td>小计</td>
				<td>操作</td>				
			</tr>
			<c:choose>
				<c:when test="${cart != null and not empty cart.items}">
					<s:form id="frm" action="/cart" method="post">
						<c:forEach items="${cart.items}" var="itm" varStatus="status" >
							<tr class="cartTabelCell">
								<td>${status.index +1 }</td>
								<td>
									<a target="_blank" 	href=""	name="productpic" title="">								
										<c:choose>
											<c:when test="${itm.value.book.coverPhoto != null and itm.value.book.coverPhoto ne ''}">
												<img src="${ctx}${itm.value.book.coverPhoto}" style="width: 60px;height: 60px;"  >
											</c:when>
											<c:otherwise>
												<img src="${ctx}/images/longtian/book_nophoto_big.gif" style="width: 60px;height: 60px;"  >
											</c:otherwise>
										</c:choose>
      									
      								</a>
      							</td>
								<td>
									<a target="_blank" href="33" name="product" title="55">${itm.value.book.name }</a>
                					<input type="hidden" id="itemId${itm.key}" value="${itm.key }"></input>
                					<input type="hidden" name="bookId" id="bookId" value="${itm.key}"></input>
                				</td>
								<td>${itm.value.book.price }</td>
								<td>0</td>
								<td>
									<input type="hidden"  id="count${itm.key}" value="${itm.value.count }"></input>
	                  				<%--onchange="modifyBookCount(${itm.key})" --%>    
	                				<input name="count"  id="count" style="width: 30px;" size="5" type="text" value="${itm.value.count }"
	                				onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onblur="this.value=this.value.replace(/[^\d]/g,'');checkBlack(this) " >           
	                			</td>								
								<td><fmt:formatNumber pattern="#,#00.00#" value="${itm.value.amount }"></fmt:formatNumber></td>
								<td>
									<a name="delete" href="${ctx}/cart/removeItem.do?item.book.id=${itm.key}" 
	                 					onclick="return confirm('确定删除吗?')"   class="">删除
	                 				</a>
	                 			</td>								
							</tr>
						</c:forEach>						
					</s:form>
				</c:when>
				<c:otherwise>
					<tr class="goShoping" >
						<td colspan="8">
							您还没有挑选图书，<a href="${ctx}/ltbook/index.do" target="_self" style="color: blue" >继续购书&gt;&gt;</a></div>				    		
						</td>
					</tr>
				</c:otherwise>
			</c:choose>
		</table>

	<c:if test="${cart != null and not empty cart.items}">
		<table class="moneyTable" align="center">		
			<tr>
				<td align="right">
					<p class="price">图书金额总计：<span class="moneyRenMinBi">￥<fmt:formatNumber pattern="#,#00.00#">${cart.total}</fmt:formatNumber></span></p>
				</td>
			</tr>
			<tr>
				<td align="right">
				<a class="goon" name="goon" target="_blank" href="${ctx}/pages/main.html">继续购书</a>
				<input type="button" onclick="modify()" value="提交修改">
	    		<input type="button" onclick="placeOrder()" value="下订单">
				</td>
			</tr>	
			<tr>
				<td align="right">
					&nbsp;
				</td>
			</tr>
			<%--
			<tr>
				<td align="right">
				<a class="goon" name="goon" target="_blank" href="${ctx}/pages/main.html">继续购书</a>
				
				</td>
			</tr>
			 --%>
									
	</table>
	</c:if>
	
      

     <form action="" id="removeFrm">
    	<input type="hidden" name="item.book.id" value=""></input>
    </form>
          <div class="clear"></div>
<script type="text/javascript">
function checkBlack(arg){
	if(arg.value == ""){
		arg.value = 0;
	}
}
function modify(){
	var frm = document.getElementById("frm");
	frm.action = '${ctx}/cart/modifyCart.do';
	frm.submit();
}
function placeOrder(){
<stc:ifNotLogin>
	Ext.MessageBox.confirm('提示','您还没有登录系统,请登录后下订单!<br>您购物车中的图书会保留,以继续使用',function(btn){
		if(btn == 'yes'){
			location.href = '${ctx}/login.jsp';
		}
	});
	//location.href = '${ctx}/login.jsp';
</stc:ifNotLogin>	
<stc:ifLogin>
	location.href = '${ctx}/front/orderForm/placeOrder.do';
</stc:ifLogin>

}
function removeItem(arg){
	if (confirm('')){
		var frm = document.getElementById("removeFrm");
		frm.action = '${ctx}/cart/removeItem.do';
		frm.item.book.id = arg;
		frm.submit();
	}
}
//修改购物车中图书数量
function modifyBookCount(arg){
	//购物车项id
	//var itemId = $("#itemId").vlaue;
	//var count  = $("#count").value;
	var itemId = document.getElementById("itemId"+arg).value;
	var count = document.getElementById("count"+arg).value;
	alert(itemId);
	alert(count);
	$.ajax({
		url : '${ctx}/cart/modifyCount.do',
		type:'post',
		dataType:'json',
		data:{
			'item.book.id' : itemId,
			'item.count'   : count
		},
		success: function(rst, textStatus){
			alert(rst);
	  		if(rst.result == "success"){
				alert("ssss");
			}else{
				alert("ffff");
			}
		}
		
	});
}
//删除购物车项
function removeCartItem(){
	
}

</script>
</body>
</html>